<script>
import stockApi from '@/api/stock/stock'
import productApi from "@/api/product/productset";
export default {
  data() {
    return {
      formData: {
      },
      tableData: null,
      current: 1, // 当前页
      limit: 1, // 每页显示记录数
      total: 0, // 总记录数
      stockInfo: {
        name: '',
        brand: '',
        model: '',
        warehouse:''
      },
      rules: {
        name: [
          { required: true, message: '请输入产品名称', trigger: 'blur' }
        ],
        brand: [
          { required: true, message: '请输入产品品牌', trigger: 'blur' }
        ],
        model: [
          { required: true, message: '请选择产品类型', trigger: 'change' }
        ],
        warehouse: [
          { required: true, message: '请输入仓库名称', trigger: 'change' }
        ]
      },
      modelclass: null
    }
  },
  created() {
    this.getdata()
    this.getclass()
  },
  methods: {
    getclass() {
      productApi.getclass().then(res => {
        this.modelclass = res.data
      })
    },
    // 获取数据
    getdata() {
      this.formData.page = this.current
      this.formData.limit = this.limit
      stockApi.getAllProduct(this.formData).then(
        res => {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      )
    },
    getPagedata(page = 1) {
      this.current = page
      this.formData.page = this.current
      this.formData.limit = this.limit
      stockApi.getAllProduct(this.formData).then(
        res => {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      )
    },
  }
}
</script>

<template>
  <div class="stock">
    <div class="search">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="产品名称">
          <el-input v-model="formData.name" placeholder="请输入产品名称" clearable/>
        </el-form-item>
        <el-form-item label="产品品牌">
          <el-input v-model="formData.brand" placeholder="请输入产品品牌" clearable/>
        </el-form-item>
        <el-form-item label="产品类型">
          <el-select v-model="formData.model" placeholder="请选择产品类型" clearable>
            <el-option
              v-for="item in modelclass"
              :key="item.id"
              :label="item.info"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="仓库名称">
          <el-input v-model="formData.warehouse" placeholder="请输入仓库名称" clearable/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getdata" style="border-radius: 10px">查询</el-button>
        </el-form-item>
      </el-form>

    </div>

    <div>
      <el-table :data="tableData" border>
        <el-table-column prop="warehouse.name" label="仓库名称" />
        <el-table-column prop="product.name" label="产品名称" />
        <el-table-column prop="product.brand" label="产品品牌" />
        <el-table-column prop="product.model.info" label="产品类型" />
        <el-table-column prop="quantity" label="库存数量" />
        <el-table-column prop="sellingPrice" label="销售价格($)" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateTime" label="库存更新时间" />
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
              <div slot="reference" class="name-wrapper">
                <el-tag v-if="scope.row.status===0" effect="dark" type="success">有货</el-tag>
                <el-tag v-if="scope.row.status===1" effect="dark" type="info">缺货</el-tag>
              </div>
          </template>
        </el-table-column>
        <el-table-column prop="updateTime" label="出库数" />
        <el-table-column prop="updateTime" label="入库数" />
      </el-table>
    </div>
    <div class="block">
      <el-pagination
        :page-size="limit"
        :total="total"
        style="padding:30px 0;text-align:center;"
        layout="total,prev,pager,next,jumper"
        @current-change="getPagedata"
      />
    </div>

  </div>
</template>



<style scoped lang="scss">
.stock{
  margin: 20px;
}
</style>


